import {
  oneDateGetNextSevenDate,
  date2day,
  date2YYYYMMDD,
  date2sevenDates
} from "../../utils/util.js";
/**
 * 处理选择服务时间界面返回的数据
 * 
 */
export function res2data(res) {
  var timeContent = [];
  var testArr = [];
  res.forEach((item, index) => {
    var schedulingDate = item.schedulingDate;
    var schedulingTime = item.schedulingTime;
    var obj1 = {};
    obj1.timeOne = `${schedulingTime}:00 上门`;
    obj1.state = item.schedulingNum < item.schedulingTotal ? 1 : 3;
    if (testArr.indexOf(schedulingDate) == -1) {
      var obj = {};
      obj.title = {}
      obj.title.active = false;
      obj.title.titleTime = `${date2day(schedulingDate)} (${date2YYYYMMDD(schedulingDate).type1})`
      obj.allTime = [];
      obj.allTime.push(obj1);
      timeContent.push(obj);
      testArr.push(schedulingDate)
    } else {
      var index = testArr.indexOf(schedulingDate);
      timeContent[index].allTime.push(obj1);
    }
  })
  timeContent.sort(function(a, b) {
    if (new Date(a.title.titleTime.slice(5, -1)).getTime() < new Date(b.title.titleTime.slice(5, -1)).getTime()) {
      return -1;
    } else if (new Date(a.title.titleTime.slice(5, -1)).getTime() > new Date(b.title.titleTime.slice(5, -1)).getTime()) {
      return 1;
    }
    return 0;
  })
  return timeContent;
}